package com.test.loader;

public class LoaderApp {

	public static void main(String[] args) {
//		try {
//			System.out.println("开始初始化");
//			Class<?> clazz = Class.forName("com.test.loader.Son");
//			System.out.println("开始构造实例");
//			clazz.newInstance();
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//		} catch (InstantiationException e) {
//			e.printStackTrace();
//		} catch (IllegalAccessException e) {
//			e.printStackTrace();
//		}
		
		try {
			System.out.println("开始初始化");
			ClassLoader loader = Thread.currentThread().getContextClassLoader().getParent();
			Class<?> clazz = loader.loadClass("com.test.loader.Son");
			System.out.println("开始构造实例");
			clazz.newInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}

}

class Son extends Father {
	static int i = 10;
	static {
		System.out.println("Son 静态代码块执行;i的值为："+i);
		
	}
	
	public Son() {
		System.out.println("Son构造函数执行;i的值为："+i);
	}
}

class Father extends GrandFather {
	static {
		System.out.println("Father 静态代码执行");
	}
	public Father() {
		System.out.println("Father 构造函数执行");
	}
}

class GrandFather {
	static {
		System.out.println("GrandFather 静态代码执行");
	}
	
	public GrandFather() {
		System.out.println("GrandFather 构造函数执行");
	}
}